package com.web.surf.sample.eshop.faces.core;

import com.web.surf.sample.eshop.utils.MessageProvider;

public abstract class AbstractValidator {

	public enum ValidationErrors {
		NAME_ERROR("nameError"),		
		ZIP_ERROR("zipError"),
		PHONE_ERROR("phoneError"),
		NUMBER_ERROR("numberError"),
		ADDRESS_ERROR("addressError");
		
		private String errorText;
		
		ValidationErrors(String errorName) {
			this.setErrorText(MessageProvider.getValue(errorName, "err"));
		}
		public void setErrorText(String errorText) {
			this.errorText = errorText;
		}
		public String getErrorText() {
			return errorText;
		}	
		
	}	
	
	protected static boolean validateName(Object value) {
		String sValue = (String) value;		
		if (!sValue.matches("[A-Z]{1}[A-Za-z]+")) {	
			return false;
		} else
			return true;
	}
	
	protected static boolean validateZip(Object value) {
		String sValue = (String) value;		
		if (!sValue.matches("[1-9]{1}[0-9]{5}")) {
			return false;
		} else
			return true;
	}
	
	protected static boolean validatePhone(Object value) {
		String sValue = (String) value;		
		if (!sValue.matches("[1-9]{1}[0-9]{11}")) {
			return false;
		} else
			return true;
	}
	
	protected static boolean validateNumber(Object value) {
		String sValue = (String) value;		
		if (!sValue.matches("[1-9]{1}[0-9]*")) {
			return false;
		} else
			return true;
	}
	
	protected static boolean validateNumberOrNull(Object value) {
		String sValue = (String) value;		
		if (!sValue.matches("[1-9]*[0-9]*")) {
			return false;
		} else
			return true;
	}
	
}
